import {SubStateMachine} from "db://assets/Script/State/SubStateMachine";
import {StateBusInterface} from "db://assets/Script/State/interface/StateBusInterface";

export class StateMachine<T> {
    //状态机
    mainMachine: SubStateMachine<T> = new SubStateMachine<T>()

    //获取当前状态
    getCurrentState(): StateBusInterface<T> {
        console.log("StateMachine获取当前状态")
        return this.mainMachine.currState
    }

    //初始状态
    startStateWith(stateEnum: T): void {
        console.log("StateMachine初始状态：", stateEnum)
        this.mainMachine.defaultState = stateEnum
        console.log("StateMachine默认状态：", stateEnum)
        this.mainMachine.transitionTo(stateEnum)
    }

    //注册状态
    registerState(stateBusInterface: StateBusInterface<T>): void {
        console.log("StateMachine注册状态：", stateBusInterface.stateEnum)
        this.mainMachine.add(stateBusInterface)
    }

    //移除状态
    removeState(stateEnum: T): void {
        console.log("StateMachine移除状态：", stateEnum)
        this.mainMachine.remove(stateEnum)
    }

    //切换状态
    transitionTo(stateEnum: T): void {
        console.log("StateMachine切换状态：", stateEnum)
        this.mainMachine.transitionTo(stateEnum)
    }

    //更新状态
    update(deltaTime: number): void {
        console.log("StateMachine更新状态：")
        this.mainMachine.update(deltaTime)
    }

}
